package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	UserType       int    `gorm:"type:int;comment:'用户的类型: 0 患者 1 管理员'"`
	Phone          string `gorm:"type:varchar(20);unique;comment:'手机号'"` //唯一索引保障登录唯一性，
	Openid         int    `gorm:"type:int;comment:'微信id'"`
	BindStatus     int    `gorm:"type:int;comment:'绑定状态 0 -未绑定微信 1 已绑定'"`
	Password       string `gorm:"type:char(32);comment:'密码'"`
	RealNameStatus int    `gorm:"type:int;comment:'实名状态 0 未实名 1 已实名'"`
	RealName       string `gorm:"type:varchar(255);comment:'真实姓名'"`
	IdCard         string `gorm:"type:char(18);comment:'真实姓名'"`
	UserStatus     int    `gorm:"type:int;comment:'用户状态 0 -正常 1 禁用'"`
}

func (u *User) GetUserMobile(db *gorm.DB, phone string) error {
	err := db.Model(&User{}).Where("phone = ?", phone).Find(&u).Error
	return err
}

func (u *User) GetUserinfo(db *gorm.DB) error {
	err := db.Model(&User{}).Find(&u).Error
	return err
}

func (u *User) GetUserinfoById(db *gorm.DB, id int) error {
	err := db.Model(&User{}).Where("id = ? ", id).Find(&u).Error
	return err
}
